package ca.usherbrooke.domus.sipnmove2.model.call.impl;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import ca.usherbrooke.domus.sipnmove2.model.call.Call;
import ca.usherbrooke.domus.sipnmove2.model.call.CallObserver;
import ca.usherbrooke.domus.sipnmove2.model.call.CallState;
import ca.usherbrooke.domus.sipnmove2.model.communication.Communication;

/**
 * Call implementation
 */
public class CallImpl implements Call {

	/**
	 * Observers of this call
	 */
	private Set<CallObserver> observers;

	/**
	 * State of this call
	 */
	private CallState state;

	/**
	 * Parameters of the call
	 */
	private Map<String, Object> parameters;

	/**
	 * Communication handled by the call
	 */
	private Communication communication;

	/**
	 * Default constructor
	 */
	public CallImpl(CallState initialState)
	{
		this.observers = new HashSet<CallObserver>();
		this.state = initialState;
	}
	
	@Override
	public void accept() {
		state.accept(this);
	}

	@Override
	public void addCallObserver(CallObserver callObserver) {
		this.observers.add(callObserver);
	}

	@Override
	public void confirm() {
		state.confirm(this);
	}

	@Override
	public void hangUp() {
		state.hangUp(this);
	}

	@Override
	public void initiate() {
		state.initiate(this);
	}

	@Override
	public void ring() {
		state.ring(this);
	}

	@Override
	public void setState(CallState callState) {
		this.state = callState;
	}

	@Override
	public CallState getState() {
		return this.state;
	}

	@Override
	public void terminate() {
		state.terminate(this);
	}

	@Override
	public Map<String, Object> getParameters() {
		return parameters;
	}

	@Override
	public void setParameters(Map<String, Object> parameters) {
		this.parameters = parameters;
	}
	
	@Override
	public Communication getCommunication() {
		return communication;
	}

	@Override
	public void setCommunication(Communication communication) {
		this.communication = communication;
	}
	
}
